import { ExpAddEffectInfo } from "../../resource/info/ExpAddEffectInfo";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { SWFInfo } from "../../../../com/gengine/resource/info/SWFInfo";
import { LayerManager } from "../../manager/LayerManager";
import { TweenMax } from "../../../../com/greensock/TweenMax";
import { AttributeText } from "../../scene/player/AttributeText";
import { AttributeValue } from "../../scene/player/AttributeValue";
import { Circ } from "../../../../com/greensock/easing/Circ";
//class ExpAddEffect
    
    export  class ExpAddEffect
    {
        constructor(arg1: ExpAddEffectInfo)
        {
            
            this._info = arg1;
            return;
        }

        public playEffect(): void
        {
            if (!this._effectStart || !this._effectEnd) 
            {
                this.loadExpEffect();
            }
            else 
            {
                this.startExpEffectPlay();
            }
            return;
        }

        /* internal  */loadExpEffect(): void
        {
            LoaderManager.instance.load("ExpEffect.swf", this.onStartEffLoaded);
            return;
        }

        /* internal  */onStartEffLoaded(arg1: SWFInfo): void
        {
            var loc1=arg1.getAssetClass("ExpEffectStart");
            var loc2=arg1.getAssetClass("ExpEffectEnd");
            this._effectStart = new loc1();
            this._effectEnd = new loc2();
            this.startExpEffectPlay();
            return;
        }

        /* internal  */onEndEffLoaded(arg1: SWFInfo): void
        {
            this._effectEnd = arg1.clip;
            this.startExpEffectPlay();
            return;
        }

        /* internal  */startExpEffectPlay(): void
        {
            if (this._info.startX == this._info.endX && this._info.startY == this._info.endY) 
            {
                this.onStartEffectComplect();
            }
            else 
            {
                this._effectStart.x = this._info.startX - 66;
                this._effectStart.y = this._info.startY - 72;
                this._effectStart.mouseEnabled = false;
                this._effectStart.mouseChildren = false;
                if (this._info.parent) 
                {
                    this._info.parent.addChild(this._effectStart);
                }
                else 
                {
                    LayerManager.msgTipLayer.addChild(this._effectStart);
                }
                this._effectStart.addEventListener(flash.events.Event.ENTER_FRAME, this.onExpStartEffEnterFrame);
                this._effectStart.gotoAndPlay(1);
            }
            return;
        }

        /* internal  */onExpStartEffEnterFrame(arg1: Object /* flash.events.Event */): void
        {
            if (this._effectStart.currentFrame == this._effectStart.totalFrames) 
            {
                this._effectStart.removeEventListener(flash.events.Event.ENTER_FRAME, this.onExpStartEffEnterFrame);
                this._effectStart.stop();
                TweenMax.to(this._effectStart, 1, {"x": this._info.endX - 66, "y": this._info.endY - 72, "onComplete": this.onStartEffectComplect});
            }
            return;
        }

        /* internal  */onStartEffectComplect(): void
        {
            if (this._effectStart && this._effectStart.parent) 
            {
                this._effectStart.parent.removeChild(this._effectStart);
            }
            this._effectStart = null;
            this._effectEnd.x = this._info.endX - 62;
            this._effectEnd.y = this._info.endY - 49;
            this._effectEnd.mouseChildren = false;
            this._effectEnd.mouseEnabled = false;
            if (this._info.parent) 
            {
                this._info.parent.addChild(this._effectEnd);
            }
            else 
            {
                LayerManager.msgTipLayer.addChild(this._effectEnd);
            }
            this._effectEnd.addEventListener(flash.events.Event.ENTER_FRAME, this.onExpEndEffEnterFrame);
            this._effectEnd.gotoAndPlay(1);
            return;
        }

        /* internal  */onExpEndEffEnterFrame(arg1: Object /* flash.events.Event */): void
        {
            if (this._effectEnd.currentFrame == this._effectEnd.totalFrames) 
            {
                this._effectEnd.removeEventListener(flash.events.Event.ENTER_FRAME, this.onExpEndEffEnterFrame);
                this._effectEnd.stop();
                if (this._effectEnd.parent) 
                {
                    this._effectEnd.parent.removeChild(this._effectEnd);
                }
                this._effectEnd = null;
                if (this._info.isFlutterWord) 
                {
                    this.startFlutterText();
                }
            }
            return;
        }

        /* internal  */startFlutterText(): void
        {
            this.attributeText = new AttributeText(new AttributeValue(this._info.attributeType, true, this._info.value));
            var loc1=this.attributeText.defaultTextFormat;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this.attributeText.defaultTextFormat = loc1;
            this.attributeText.width = 200;
            this.attributeText.scaleX = 0.5;
            this.attributeText.scaleY = 0.5;
            this.attributeText.x = this._info.endX - 0.5 * 0.5 * this.attributeText.textWidth;
            this.attributeText.y = this._info.endY + 30;
            LayerManager.msgTipLayer.addChild(this.attributeText);
            var loc2=this._info.endX - 0.5 * this.attributeText.textWidth;
            var loc3=this._info.endY - 100;
            TweenMax.to(this.attributeText, this._info.time, {"x": loc2, "y": loc3, "scaleX": 1, "scaleY": 1, "ease": Circ.easeOut, "onComplete": this.flutterTextComplete});
            return;
        }

        /* internal  */flutterTextComplete(): void
        {
            if (this.attributeText.parent) 
            {
                this.attributeText.parent.removeChild(this.attributeText);
            }
            this.attributeText = null;
            return;
        }

        /* internal */ /* var */_info: ExpAddEffectInfo;

        /* internal */ /* var */_effectStart: Object /* flash.display.MovieClip */;

        /* internal */ /* var */_effectEnd: Object /* flash.display.MovieClip */;

        /* internal */ /* var */attributeText: AttributeText;
    }
